<template>
	<view>
		<!-- 所有内容的容器 -->
		<!--关注个人基本信息-->
		<view class="u-m-t-20">
			<!-- 头像 -->
			<u-avatar :src="OtherUserInfo.imagepath" size="large"></u-avatar>
			<u-cell-item style="float: right;width: 80%;" :arrow="arrow">
				<!-- 取消关注（已关注）图标 -->
				<u-icon v-if="fo" name="plus" size="50" color="#2979ff" @click="focus()"></u-icon>
				<!-- 关注图标 -->
				<u-icon v-else="fo" name="checkmark" size="50" color="#fa3534" @click="cancleFocus()"></u-icon>
				<!-- 消息提示 -->
				<u-toast ref="uToast" />
			</u-cell-item>
		</view>
		<!-- 个人信息展示 -->
		<view class="u-m-t-20">
			<u-cell-item title="姓名" :value="OtherUserInfo.username" :arrow="arrow"></u-cell-item>
			<u-cell-item v-if="OtherUserInfo.sex == '1'" title="性别" value="男" :arrow="arrow"></u-cell-item>
			<u-cell-item v-else="OtherUserInfo.sex == '2'" title="性别" value="女" :arrow="arrow"></u-cell-item>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				title: '其它用户详情',
				//当前用户信息
				userInfo: this.$store.state.user.userInfo,
				//关注个人用户信息
				OtherUserInfo:{},
				arrow:false,
				fo:"",
				row:""
				
			}
		},
		onLoad(option) {
			console.log('接收参数' + option.userId);
			//根据用户id查询用户信息
			uni.request({
			    url: this.$url + 'userinfo/getUserInfoByUserId', 
			    data: {
			        userId:option.userId
			    },
			    success: (res) => {
			        console.log("后台返回的数据：" + res.data.data);
					this.$data.OtherUserInfo = res.data.data;
			    },
			});
			//根据userId和foucusId查询是否被关注
			uni.request({
			    url: this.$url + 'focus/isFocus',
			    data: {
					focusId:option.userId,
			        userId:this.$data.userInfo.userid
			    },
			    success: (res) => {
			        console.log("后台返回的数据：" + res.data.data);
				   //如果被关注
				   if(res.data.data > 0){
				   	this.$data.fo = false;
				   }else{
				   	//如果没被关注
				   	this.$data.fo = true;
				   }
			    }
			});
			
		},methods:{
			//点击关注图标
			focus(){
				//关注
				uni.request({
				    url: this.$url + 'focus/insert',
				    data: {
						focusId:this.$data.OtherUserInfo.userid,
				        userId:this.$data.userInfo.userid
				    },
				    success: (res) => {
				        console.log("后台返回的数据：" + res.data.data);
					   //如果关注成功
					   if(res.data.data > 0){
					   	this.$data.fo = false;
						//消息提示
						this.$refs.uToast.show({
							title: '关注成功！可在关注中私聊！',
							type: 'success',	
						});	
					   }else{
					   	//如果没被关注
					   	this.$data.fo = true;
						//消息提示
						this.$refs.uToast.show({
							title: '关注失败！',
							type: 'error',	
						});	
					   }
				    }
				});
			},
			//点击取消关注图标
			cancleFocus(){
				//取消关注
				uni.request({
				    url: this.$url + 'focus/delete',
				    data: {
						focusId:this.$data.OtherUserInfo.userid,
				        userId:this.$data.userInfo.userid
				    },
				    success: (res) => {
				        console.log("后台返回的数据：" + res.data.data);
					   //如果取消成功
					   if(res.data.data > 0){
					   	this.$data.fo = true;
						//消息提示
						this.$refs.uToast.show({
							title: '取消关注成功！',
							type: 'success',	
						})	
					   }else{
					   	//如果取消失败
					   	this.$data.fo = false;
						//消息提示
						this.$refs.uToast.show({
							title: '取消关注失败！',
							type: 'error',	
						})	
					   }
				    }
				});
			}
		}
	}
</script>

<style>
	
	
</style>


